package org.openintents.droidcon.cloud.mvc;

import java.util.List;

import org.openintents.droidcon.cloud.model.Panel;
import org.openintents.droidcon.cloud.model.Room;
import org.openintents.droidcon.cloud.model.Schedule;
import org.openintents.droidcon.cloud.model.Slot;

public class ScheduleList {

	private List<Schedule> schedules;

	public ScheduleList(List<Schedule> schedules) {
		this.schedules = schedules;
	}

	public String display() {
		String output = "<h2>Exisiting Schedules:</h2>" + "<ul>";
		for (Schedule s : schedules) {
			output += "<li>" + s.getName() +"/" + s.getDateString() +"/" + s.getVersion() + " <a href=\"?id=" + s.getId()
					+ "&amp;action=edit\">[edit]</a> <a href=\"?id="
					+ s.getId() + "&amp;action=delete\">[delete]</a>";

			output += "<br/>Rooms: <ul>";
			for (Room r : s.getRooms()) {
				output += "<li>" + r.getName() + "/" + r.getAlias() + " <a href=\"?id=" + s.getId()
						+ "&amp;action=editRoom&amp;roomId="
						+ r.getId().getId() + "\">[edit]</a> <a href=\"?id="
						+ s.getId() + "&amp;action=deleteRoom&amp;roomId="
						+ r.getId().getId() + "\">[delete]</a>" + "</li>";
			}
			output += "</ul>";

			output += "Panels: <ul>";
			for (Panel p : s.getPanels()) {
				output += "<li>" + p.getFromTo() 
						+ "<a href=\"?id=" + s.getId()
						+ "&amp;action=editPanel&amp;panelId="
						+ p.getId().getId() + "\">[edit]</a> <a href=\"?id="
						+ s.getId() + "&amp;action=deletePanel\">[delete]</a>";

				output += "<br/>Slots: <ul>";
				for (Slot slot : p.getSlots()) {
					output += "<li>" + slot.getTitle() + " <a href=\"?id="
							+ s.getId() + "&amp;action=editSlot&amp;panelId="
							+ p.getId().getId() + "&amp;slotId="
							+ slot.getId().getId()
							+ "\">[edit]</a> <a href=\"?id=" + s.getId()
							+ "&amp;action=deleteSlot&amp;panelId="
							+ p.getId().getId() + "&amp;slotId="
							+ slot.getId().getId() + "\">[delete]</a>"
							+ "</li>";
				}
				output += "</ul></li>";
			}
			output += "</ul></li>";

		}
		output += "</ul>";
		return output;
	}
}
